<template>
  <view class="container">
	  <h1><navigator url="/pages/index/login/login" open-type="navigate">
	  <text>中国儿童银行</text>
	  		 </navigator></h1>
	  <br/>
    <view class="tip">亲爱的：{{name}}，您现在要存钱了，财富来源于积累，你是最棒的孩子，以后一定是个大富翁。</view>
    <view class="input-area">
      <input type="number" placeholder="请输入取款金额" v-model="amount" />
      <input type="password" placeholder="请输入密码" v-model="password" />
	  <input type="remark" placeholder="备注" v-model="remark" />
    </view>
    <button class="withdraw-btn" @click="handleWithdraw">确定存款</button>
  </view>
</template>

<script>
export default {
	async onLoad(options) {
		this.id=options.id
		
	    // options 是一个对象，包含了传递过来的参数
	    // 在这里，可以通过 options.id 来获取传递的参数值
	    console.log(options.id); // 输出: 123
		this.name=options.name;
		let u=await this.$api.get(this.$api.prop().serviceUrl+"/common/model/queryById/?id="+options.id+"&modelName=bankRecord",{});
		this.bankRecords=u.data;
	  },
  data() {
    return {
      amount: '',
      password: '',
	  name:"",
	  id:0,
	  remark:""
    };
  },
  methods: {
    async handleWithdraw() {
      if (this.amount && this.password) {
		  //let u=await this.$api.get(this.$api.prop().serviceUrl+"/common/model/queryById/?id="+options.id+"&modelName=bankRecord",{});
		  let u=await this.$api.get(this.$api.prop().serviceUrl+"/common/addBackRecord/?type=1&id="+this.id+"&money="+this.amount+"&pwd="+this.password+"&remark="+this.remark,{});
		  
		 
        // 在这里处理取款逻辑
		if (u.code==1){
			this.$api.alert("存款成功，你离大富翁更近了")
			this.$api.navigateTo('/pages/detail/detail?id='+this.id+'&name='+this.name)
		}else{
				this.$api.alert(u.data)
			}
          
      } else {
        uni.showToast({
          title: '请输入完整的取款信息',
          icon: 'none',
        });
      }
    },
  },
};
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.tip {
  font-size: 16px;
  color: #333;
  margin-bottom: 20px;
  word-wrap: break-word;
  width: 80%;
}
.input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80%;
}
input {
  width: 100%;
  margin-bottom: 10px;
}
.withdraw-btn {
  background-color: lightgreen;
  color: white;
  border-radius: 5px;
  padding: 10px 20px;
  text-align: center;
  width: 80%;
  margin-top: 20px;
}
input {
  width: 100%;
  margin-bottom: 10px;
  border: 1px solid black; /* 添加黑色边缘 */
}
</style>
